package com.bll.imple.honourAction;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.bean.HonourBean;
import com.bll.Action;
import com.dao.HonourDao;
import com.dao.Page;

public class ShowHonourAction implements Action {

	public String execute(HttpServletRequest request,
			HttpServletResponse response) {
		
		HttpSession session=request.getSession();
		int userId=Integer.parseInt(session.getAttribute("userId").toString());
		String lujing=request.getParameter("lujing");
	    HonourDao dao=new HonourDao();
	    List<HonourBean> list =dao.selectByUserId(userId);
	    int totalRows=list.size();
	    int rowsPerPage=5;
	    int currentPage=1;
	    int totalPages=Page.computer(totalRows, rowsPerPage);
		if(request.getParameter("currentPage")!=null){
			currentPage=Integer.parseInt(request.getParameter("currentPage"));
			if(currentPage<1){
			
				currentPage=1;
			}else if(currentPage>totalPages){
			
				currentPage=totalPages;
			}
		}
		int currentRows=(currentPage-1)*rowsPerPage;
//		if(request.getParameter("currentRows")!=null){
//			currentRows=Integer.parseInt(request.getParameter("currentRows"));
//		}
		//System.out.println("currenet:"+currentRows);
	    
		request.setAttribute("currentPage", currentPage);
	    request.setAttribute("totalPages", totalPages);
//	    request.setAttribute("rowsPerPage", rowsPerPage);
	    List<HonourBean> hon=dao.selectPages(currentRows, rowsPerPage, userId);
	   // System.out.println("bean:"+bean);
	    request.setAttribute("list", hon);
		return lujing;
	}
	
	

}
